<script setup>
import { appStockListQuery } from "@/services/cashier";
import { onLoad, onReady, onShow } from "@dcloudio/uni-app";
import { nextTick, ref, watch, onMounted } from "vue";
import { appEmployeeSelector } from "@/services/transfer";

const userObj = ref({});
const openList = ref([]);
const form = ref({
  name: "",
});
const selectId = ref("");
const topHeight = ref(uni.getStorageSync("topHight") || 0);
onLoad((e) => {
  if (uni.getStorageSync("user")) {
    userObj.value = JSON.parse(uni.getStorageSync("user"));
  }
  getAppEmployeeSelector();

  console.log("onLoad", userObj.value);
});
onReady(() => {
  // 微信小程序需要用此写法
  // datetimePickerRef.value.setFormatter(formatter);
});
const selectShow = ref(false);

const getAppEmployeeSelector = async () => {
  let res = await appEmployeeSelector({
    shopId: userObj.value.shopId,
    available: true,
    name: form.value.name,
  });
  openList.value = res.data.datas;
};
function open() {
  // 打开逻辑，比如设置 show 为 true
  // selectShow.value = true;
  // console.log('open');
}
const selectItemObj = ref({});
const selectItem = (item) => {
  if (selectId.value == item.id) {
    selectId.value = "";
  } else {
    selectId.value = item.id;
    selectItemObj.value = item;
  }
};
const selectTo = () => {
  uni.setStorageSync("selectSearch", selectItemObj.value);
  uni.navigateBack();
};
const NoSelect = () => {
  uni.navigateBack();
};
</script>

<template>
  <view class="bg">
    <top-nav :title="'选择操作人'" :border="false" rType="save"></top-nav>

    <view class="top" :style="'top: calc( 88rpx + ' + topHeight + 'px);'">
      <up-search
        shape="square"
        placeholder="姓名"
        v-model="form.name"
        :showAction="false"
        @search="searchFun"
      ></up-search>
    </view>
    <view class="content">
      <view class="content-list">
        <view
          class="content-item"
          v-for="(item, index) in openList"
          :key="index"
          @click="selectItem(item)"
        >
          <view class="content-item-left">{{ item.name }}</view>
          <view class="content-item-right"
            ><text></text>
            <view class="no_select" v-if="selectId != item.id"></view>
            <view class="select" v-if="selectId == item.id">
              <up-icon
                name="checkmark-circle-fill"
                color="#2979ff"
                size="50rpx"
              ></up-icon>
            </view>
          </view>
        </view>
      </view>
    </view>

    <view class="bt-bt">
      <view class="popup-content-btn">
        <up-button
          class="bt-qx"
          type="default"
          :plain="true"
          text="取消"
          @click="NoSelect()"
        ></up-button>
        <up-button type="primary" @click="selectTo()" text="确定"></up-button>
      </view>
    </view>
  </view>
</template>

<style lang="scss" scoped>
@import "index.scss";
</style>
